<?php

namespace App\Http\Controllers\Admin\Permission;

use App\Repository\RoleUserRepository;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class RoleUserController extends Controller
{
    
    protected $roleUser;

    public function __construct(RoleUserRepository $roleUser)
    {
        $this->roleUser = $roleUser;
    }
    
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id Role id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $roles = $this->roleUser->findByAdmin($id, ['role_id']);

        return $roles->pluck('role_id')->all();
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        if(!\Entrust::can('admin_role_setting')){
            abort(403, '你没有权限进行此操作');
        }

        $this->roleUser->updateByAdmin($id, $request->get('role_id'));
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
